package cn.fly.chatgpt.service.Impl;

import cn.fly.chatgpt.domain.entity.Ans;
import cn.fly.chatgpt.domain.entity.Chatgpt;
import cn.fly.chatgpt.domain.entity.Dialogue;
import cn.fly.chatgpt.domain.entity.Qus;
import cn.fly.chatgpt.mapper.ChatgptMapper;
import cn.fly.chatgpt.service.ChatgptService;
import cn.hutool.Hutool;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.lang.generator.SnowflakeGenerator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Service
public class ChatgptServiceImpl implements ChatgptService {

    @Resource
    private ChatgptMapper chatgptMapper;


    @Override
    public Dialogue getMyDialogue(Integer userId, Long chatId) {
        System.out.println(userId);
        List<Chatgpt> list = chatgptMapper.getMyDialogue(userId, chatId);

        List<Qus> qus = new ArrayList<>();
        List<Ans> ans = new ArrayList<>();

        list.forEach(l -> {
            qus.add(new Qus(l.getQuestion(), l.getQusTime()));
            ans.add(new Ans(l.getAnswer(), l.getAnsTime()));
        });

        return new Dialogue(qus, ans);
    }

    @Override
    public void addInfo(Chatgpt chatgpt) {
        chatgptMapper.addInfo(chatgpt);
    }

    @Override
    public List<Long> getChatList(Integer userId) {
        return chatgptMapper.getChatList(userId);
    }

    @Override
    public void newChat(Integer userId) {
        SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator();
        Long chatId = snowflakeGenerator.next();
        chatgptMapper.newChat(chatId, userId);
    }
}
